package cn.stylefeng.guns.modular.lx.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.lx.entity.LxTypeLwh;
import cn.stylefeng.guns.modular.lx.mapper.LxTypeLwhMapper;
import cn.stylefeng.guns.modular.lx.model.params.LxTypeLwhParam;
import cn.stylefeng.guns.modular.lx.model.result.LxTypeLwhResult;
import  cn.stylefeng.guns.modular.lx.service.LxTypeLwhService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lwh
 * @since 2023-12-20
 */
@Service
public class LxTypeLwhServiceImpl extends ServiceImpl<LxTypeLwhMapper, LxTypeLwh> implements LxTypeLwhService {

    @Override
    public void add(LxTypeLwhParam param){
        LxTypeLwh entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(LxTypeLwhParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(LxTypeLwhParam param){
        LxTypeLwh oldEntity = getOldEntity(param);
        LxTypeLwh newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public LxTypeLwhResult findBySpec(LxTypeLwhParam param){
        return null;
    }

    @Override
    public List<LxTypeLwhResult> findListBySpec(LxTypeLwhParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(LxTypeLwhParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public List<LxTypeLwhResult> findGetType(LxTypeLwhParam lxOrderLwhParam) {
        return this.baseMapper.findGetType();
    }

    private Serializable getKey(LxTypeLwhParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private LxTypeLwh getOldEntity(LxTypeLwhParam param) {
        return this.getById(getKey(param));
    }

    private LxTypeLwh getEntity(LxTypeLwhParam param) {
        LxTypeLwh entity = new LxTypeLwh();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
